package com.ruoyi.settled.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.settled.domain.PartnerTable;
import com.ruoyi.settled.service.IPartnerTableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合作方Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/settled/partner")
public class PartnerTableController extends BaseController
{
    @Autowired
    private IPartnerTableService partnerTableService;

    /**
     * 查询合作方列表
     */
    @PreAuthorize("@ss.hasPermi('settled:partner:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartnerTable partnerTable)
    {
        startPage();
        List<PartnerTable> list = partnerTableService.selectPartnerTableList(partnerTable);
        return getDataTable(list);
    }


    /**
     * 根据用户名名称获取合作方编码
     */
    @PostMapping("/getPartnerCodeByUserName")
    public AjaxResult getPartnerCodeByUserName(@RequestBody String userName){
        return success(partnerTableService.selectPartnerCodeByUserName(userName));
    }




    /**
     * 导出合作方列表
     */
    @PreAuthorize("@ss.hasPermi('settled:partner:export')")
    @Log(title = "合作方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartnerTable partnerTable)
    {
        List<PartnerTable> list = partnerTableService.selectPartnerTableList(partnerTable);
        ExcelUtil<PartnerTable> util = new ExcelUtil<PartnerTable>(PartnerTable.class);
        util.exportExcel(response, list, "合作方数据");
    }

    /**
     * 获取合作方详细信息
     */
    @PreAuthorize("@ss.hasPermi('settled:partner:query')")
    @GetMapping(value = "/{partnerCode}")
    public AjaxResult getInfo(@PathVariable("partnerCode") String partnerCode)
    {
        return success(partnerTableService.selectPartnerTableByPartnerCode(partnerCode));
    }

    /**
     * 新增合作方
     */
    @PreAuthorize("@ss.hasPermi('settled:partner:add')")
    @Log(title = "合作方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartnerTable partnerTable)
    {
        return toAjax(partnerTableService.insertPartnerTable(partnerTable));
    }

    /**
     * 修改合作方
     */
    @PreAuthorize("@ss.hasPermi('settled:partner:edit')")
    @Log(title = "合作方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartnerTable partnerTable)
    {
        return toAjax(partnerTableService.updatePartnerTable(partnerTable));
    }

    /**
     * 删除合作方
     */
    @PreAuthorize("@ss.hasPermi('settled:partner:remove')")
    @Log(title = "合作方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partnerCodes}")
    public AjaxResult remove(@PathVariable String[] partnerCodes)
    {
        return toAjax(partnerTableService.deletePartnerTableByPartnerCodes(partnerCodes));
    }
}
